import { makeAutoObservable } from 'mobx';

export type Status = 'pending' | 'loading' | 'success' | 'error';
const TARGET_FORMAT = [
  {
    name: 'MP4',
    encoder: [
      {
        label: 'H.264',
        value: 'h264'
      },
      {
        label: 'MPEG-1',
        value: 'mpeg1video'
      },
      {
        label: 'MPEG-2',
        value: 'mpeg2video'
      },
      {
        label: 'MPEG-4',
        value: 'msmpeg4'
      },
      {
        label: 'H.265',
        value: 'libx265'
      },
      {
        label: 'vp9',
        value: 'vp9'
      }
    ]
  },
  {
    name: 'FLV',
    encoder: [
      {
        label: 'FLV',
        value: 'flv'
      },
      {
        label: 'H.264',
        value: 'h264'
      }
    ]
  },
  {
    name: 'AVI',
    encoder: [
      {
        label: 'MPEG-4',
        value: 'msmpeg4'
      },
      {
        label: 'MPEG-1',
        value: 'mpeg1video'
      },
      {
        label: 'MPEG-2',
        value: 'mpeg2video'
      }
    ]
  },
  {
    name: 'MOV',
    encoder: [
      {
        label: 'H.264',
        value: 'h264'
      },
      {
        label: 'MPEG-4',
        value: 'msmpeg4'
      },
      {
        label: 'MPEG-1',
        value: 'mpeg1video'
      },
      {
        label: 'MPEG-2',
        value: 'mpeg2video'
      }
    ]
  },
  {
    name: 'F4V',
    encoder: [
      {
        label: 'H.264',
        value: 'h264'
      }
    ]
  },
  {
    name: '3GP',
    encoder: [
      {
        label: 'H.264',
        value: 'h264'
      },
      {
        label: 'MPEG-4',
        value: 'msmpeg4'
      }
    ]
  }
];
class Store {
  constructor() {
    makeAutoObservable(this);
  }

  originFiles: File[] = [];
  formatStatus: Status[] = [];
  currentFormat = 'MP4';
  currentEncoderList: { label: string; value: string }[] = TARGET_FORMAT[0].encoder;
  currentEncoder = this.currentEncoderList[0].value;
  targetFormat = TARGET_FORMAT;
  setStore = (
    data: Partial<{
      originFiles: File[];
      formatStatus: Status[];
      currentFormat: string;
      currentEncoderList: { label: string; value: string }[];
      currentEncoder: string;
    }>
  ) => {
    Object.keys(data).forEach((key) => {
      this[key] = data[key];
    });
  };
}

export default new Store();
